package com.ctcemti.mdm.project.common.excelverifyhandler;

import cn.afterturn.easypoi.excel.entity.result.ExcelVerifyHandlerResult;
import cn.afterturn.easypoi.handler.inter.IExcelVerifyHandler;
import com.ctcemti.mdm.project.sys.dao.ResEntElementTreeMapper;
import com.ctcemti.mdm.project.sys.entity.ResEntElementTree;
import tk.mybatis.mapper.util.StringUtil;

import java.util.ArrayList;
import java.util.List;

public class ExcelVerifyHandlerToEBSTree implements IExcelVerifyHandler<ResEntElementTree> {

    private List<String> listCode;

    private ResEntElementTreeMapper resEntElementTreeMapper;

    @Override
    public ExcelVerifyHandlerResult verifyHandler(ResEntElementTree resEntElementTree) {

        ExcelVerifyHandlerResult result = new ExcelVerifyHandlerResult();

        if(listCode!=null && listCode.size()>0){
            if(listCode.contains(resEntElementTree.getEbs())){
                result.setMsg("该编码表格中已存在");
                result.setSuccess(false);
                return result;
            }
        }
        ResEntElementTree entity = new ResEntElementTree();
        entity.setEbs(resEntElementTree.getEbs());
        List<ResEntElementTree> list =  resEntElementTreeMapper.select(entity);
        if(!StringUtil.isEmpty(resEntElementTree.getEbs()) && list.size()>0){
            result.setMsg("该编码数据库中已存在");
            result.setSuccess(false);
            return result;
        }else{
            listCode.add(resEntElementTree.getEbs());
        }
        result.setSuccess(true);
        return result;
    }

    public ExcelVerifyHandlerToEBSTree(Object object){
        this.listCode = new ArrayList<String>();
        this.resEntElementTreeMapper = (ResEntElementTreeMapper) object;

    }
}
